// pages/info_details.js
var app = getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    phone: '',
    name:'',
    sex:'',
    fresh_year:'',
    degree:'',
    wx_id:'',
    birthday:'',
    intro:'',
    src:'',
    edit_flag:0,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var openid = options.open_id;
    var user_openid = app.globalData.openid;
    console.log('openid=' + openid);
    console.log('user_openid=' + user_openid);
    if (openid){
      if(openid == user_openid){
        this.setData({ edit_flag:1});
      }
      var that = this;
      wx.request({
        url: app.globalData.query_ip + '/wx_user_details',  // 查询用户信息
        method: 'GET',
        data: {
          openid: openid,
        },
        header: {
          'content-type': 'application/json' 
        },
        success: function (res) {
          var d = res.data;
          //console.log('d =====' + d);
          that.setData({ 
            phone: d.phone, 
            name: d.name, 
            sex: d.sex, 
            degree: d.degree, 
            fresh_year: d.fresh_year,
            wx_id:d.wx_id,
            intro:d.intro,
            birthday:d.birthday,       
          });
          wx.downloadFile({
            url: app.globalData.query_ip + '/download/' + d.file_name, //下载头像
            success(res) {
              if (res.statusCode === 200) {
                that.setData({ src: res.tempFilePath });
              }
            },
          });
        },
      });
    }else{
      wx.redirectTo({
        url: '../login/login',
      })
    }
  },
  edit_details:function(){
      var data = 'phone='+this.data.phone;
      data += '&name='+this.data.name;
      data += '&sex='+this.data.sex;
      data += '&fresh_year='+this.data.fresh_year;
      data += '&degree='+this.data.degree;
      wx.redirectTo({
        url: '../info_edit/info_edit?'+data,
      });
  }
})